package com.xx.pmis.persistence.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import com.xx.pmis.model.Card;

public class CardDAOImpl extends BaseHibernateDAOImpl<Card> implements CardDAO {

	public Card getCardByCardID(String cardID) {
		Card card;
		try {
			card = (Card) getSession().get(Card.class, cardID);

		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return card;
	}

	@SuppressWarnings("unchecked")
	public List<Card> getAllCard() {
		List<Card> cards;
		try {
			Query query = getSession().getNamedQuery("AllCardQuery");
			cards = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return cards;
	}

	@SuppressWarnings("unchecked")
	public List<Card> getAllCardByPage(int currentPage, int lineSize) {
		List<Card> cards;
		try {
			Query query = getSession().getNamedQuery("AllCardByPageQuery");
			query.setFirstResult((currentPage - 1) * lineSize);
			query.setMaxResults(lineSize);
			cards = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return cards;
	}

}
